package com.SpringMVC.controller;

import com.SpringMVC.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

/**
 * @author:liuwei
 * @creatdate:2022-02-28-19:12
 */
@Controller
public class ParamController {
	@RequestMapping("/testServletAPI")
	public String testServletAPI(HttpServletRequest request){
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		System.out.println("username:"+username+","+"password:"+password);
		return "success";
	}

	@RequestMapping("/testParam")
	public String testServletAPI(String username,String password,String[] hobby){
		//多请求参数中出现多个同名的请求参数，可以在控制器方法的形参位置设置字符串类型或字符串数组接受次请求参数
		//如果是字符串类型的形参，最终结果为请求参数的每一个值直接使用逗号拼接
		System.out.println("username:"+username+","+"password:"+password+","+"hobby:"+ Arrays.toString(hobby));
		return "success";
	}

	@RequestMapping(value = "/testPOJO")
	public String testPOJO(User user){
		System.out.println(user);
		return "success";
	}
}
